// src/stores/userStore.ts
// src/stores/userStore.ts
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state: () => ({
    isLoggedIn: false,
    username: '',
    userId: null, // 添加 userId 到 state
  }),
  actions: {
    login(username: string, userId: any) {
      this.isLoggedIn = true;
      this.username = username;
      this.userId = userId; // 使用 userId
      localStorage.setItem('username', username);
      localStorage.setItem('userId', userId); // 存储 userId 到 localStorage
    },
    logout() {
      this.isLoggedIn = false;
      this.username = '';
      this.userId = null; // 清空 userId
      localStorage.removeItem('username');
      localStorage.removeItem('userId'); // 移除 userId 从 localStorage
    },
  },
});